﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChessSuite.Utilities.Common.Enumeations;

namespace ChessSuite.Utilities.Common.Utilities
{
    public static partial class PieceTypeUtility
    {
        public static bool IsBasicPiece(this PieceType piece)
        {
            return piece == PieceType.Pawn ||
                piece == PieceType.Bishop ||
                piece == PieceType.Knight ||
                piece == PieceType.Rook ||
                piece == PieceType.Queen ||
                piece == PieceType.King;
        }

        #region Comparison of individual instances.
        public static bool IsPiece(this PieceType piece, PieceType value)
        {
            if (!value.IsBasicPiece())
                throw new ArgumentOutOfRangeException("value", Resources.PIECE_COMPARISON_EXCEPTION_ONLY_BASIC_PIECES_ALLOWED_FOR_COMPARISON);

            return piece == value;
        }
        public static bool HasPiece(this PieceType piece, PieceType value)
        {
            if (!value.IsBasicPiece())
                throw new ArgumentOutOfRangeException("value", Resources.PIECE_COMPARISON_EXCEPTION_ONLY_BASIC_PIECES_ALLOWED_FOR_COMPARISON);

            return 0 != (piece & value);
        }

        public static bool IsEmpty(this PieceType piece)
        {
            return piece == PieceType.None;
        }

        public static bool IsPawn(this PieceType piece)
        {
            return piece.IsPiece(PieceType.Pawn);
        }
        public static bool HasPawn(this PieceType piece)
        {
            return piece.HasPiece(PieceType.Pawn);
        }

        public static bool IsBishop(this PieceType piece)
        {
            return piece.IsPiece(PieceType.Bishop);
        }
        public static bool HasBishop(this PieceType piece)
        {
            return piece.HasPiece(PieceType.Bishop);
        }

        public static bool IsKnight(this PieceType piece)
        {
            return piece.IsPiece(PieceType.Knight);
        }
        public static bool HasKnight(this PieceType piece)
        {
            return piece.HasPiece(PieceType.Knight);
        }

        public static bool IsRook(this PieceType piece)
        {
            return piece.IsPiece(PieceType.Rook);
        }
        public static bool HasRook(this PieceType piece)
        {
            return piece.HasPiece(PieceType.Rook);
        }

        public static bool IsQueen(this PieceType piece)
        {
            return piece.IsPiece(PieceType.Queen);
        }
        public static bool HasQueen(this PieceType piece)
        {
            return piece.HasPiece(PieceType.Queen);
        }

        public static bool IsKing(this PieceType piece)
        {
            return piece.IsPiece(PieceType.King);
        }
        public static bool HasKing(this PieceType piece)
        {
            return piece.HasPiece(PieceType.King);
        }
        #endregion
    }
}
